import common
import DCOracle2.dco2
import unittest

class test_dco2_connect(common.TestCase):

    def setUp(self):

        username, password, dbname = self._getConnDetails()
        self.db = db = DCOracle2.dco2.connect(username,password,dbname)
        c = db.cursor()
        c.prepare("select * from EMP")
        c.execute()
        self.c = c
        self.f = c.fetch(5)


    def test_cursorDescribe(self):
        self.assertEqual(list(self.c.describe()),
                         [('EMPNO', 2, 22, 22, 4, 0, 0),
                          ('ENAME', 1, 10, 10, 0, 0, 1),
                          ('JOB', 1, 9, 9, 0, 0, 1),
                          ('MGR', 2, 22, 22, 4, 0, 1),
                          ('HIREDATE', 12, 7, 7, 0, 0, 1),
                          ('SAL', 2, 22, 22, 7, 2, 1),
                          ('COMM', 2, 22, 22, 7, 2, 1),
                          ('DEPTNO', 2, 22, 22, 2, 0, 1)])

    def test_result(self):
        f = self.f
        self.assertEqual(len(f),8)
        self.assertEqual(len(f[0]),5)
        self.failUnless(isinstance(f[0],DCOracle2.dco2.ResultSetType))
        self.assertEqual(len(f[1]),5)
        self.failUnless(isinstance(f[1][0],DCOracle2.dco2.ResultSetItemType))
        self.assertEqual(self.f[0][1].value(),7499)

if __name__ == '__main__':
        unittest.main()
